/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InterfazReporteLaboratorio.java
 *
 * Created on 26/12/2011, 03:45:28 AM
 */

package presentacion;

import Paneles.PanelGeneral;
import business.AsignaturaBO;
import business.LaboratorioBO;
import dominio.Asignatura;
import dominio.Laboratorio;
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.TableColumn;
import javax.swing.table.DefaultTableModel;
import javax.swing.ImageIcon;
/**
 *
 * @author KOFMASTER
 */
public class InterfazReporteLaboratorio extends javax.swing.JFrame {
    
    private ImageIcon icono;
    
     private AsignaturaBO asignaturabo = new AsignaturaBO();
     private LaboratorioBO  laboratoriobo;
    /** Creates new form InterfazReporteLaboratorio */
    public InterfazReporteLaboratorio() {
        initComponents();
         PanelGeneral panel=new PanelGeneral();
         this.add(panel,BorderLayout.SOUTH);
         icono = new ImageIcon(getClass().getResource("/Imagenes/icon.gif"));
         this.setIconImage(icono.getImage());



        TableColumn  column = null;

         /*Cambio el ancho de las columnas de la tabla jTable1*/
        column = this.jTable1.getColumnModel().getColumn(0);
        column.setPreferredWidth(85);
        column = this.jTable1.getColumnModel().getColumn(1);
        column.setPreferredWidth(100);
        column = this.jTable1.getColumnModel().getColumn(2);
        column.setPreferredWidth(100);
        column = this.jTable1.getColumnModel().getColumn(3);
        column.setPreferredWidth(120);
        column = this.jTable1.getColumnModel().getColumn(4);
        column.setPreferredWidth(120);


        laboratoriobo =new LaboratorioBO();
        this.inicializarTablaLaboratorio();

    }


    private void inicializarTablaLaboratorio(){
        List<Laboratorio> listaLaboratorio=laboratoriobo.obtenerListLaboratorio();
        int numfilas = listaLaboratorio.size();

       jTable1.setModel(new DefaultTableModelImpl(
            new Object[numfilas][5],
            new String [] {
                "Número", "Nombre", "Capacidad", "Disponible", "Descripcion"
            }));


        for (int indicefilas = 0; indicefilas < numfilas; indicefilas++) {
            this.jTable1.setValueAt(listaLaboratorio.get(indicefilas).getIdLaboratorio(), indicefilas, 0);
            this.jTable1.setValueAt(listaLaboratorio.get(indicefilas).getnombreLab(), indicefilas, 1);
            this.jTable1.setValueAt(listaLaboratorio.get(indicefilas).getcapacidadlab(), indicefilas, 2);
            this.jTable1.setValueAt(listaLaboratorio.get(indicefilas).getdisponibildaLab(), indicefilas, 3);
            this.jTable1.setValueAt(listaLaboratorio.get(indicefilas).getdescripcionLab(), indicefilas, 4);

        }
    }


    private class DefaultTableModelImpl extends DefaultTableModel {

        public DefaultTableModelImpl(Object[][] arg0, Object[] arg1) {
            super(arg0, arg1);
        }
        boolean[] canEdit = new boolean[]{false, false, false, false, false, true};

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();

        setTitle("Reporte Laboratorio");
        setResizable(false);

        jLabel1.setText("Seleccione el laboratorio a consultar:");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Numero ", "Nombre", "Capacidad", "Disponible", "Descripcion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Boolean.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Consultar Información Laboratorio");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Capacidad del Laboratorio:");

        jTextField1.setEditable(false);

        jLabel4.setText("Descripción del Laboratorio:");

        jTextField2.setEditable(false);

        jButton2.setText("Aceptar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel2.setText("Asignatura");

        jTextField3.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 789, Short.MAX_VALUE)
                            .addComponent(jLabel1)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(168, 168, 168)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(157, 157, 157)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 258, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(14, 14, 14)
                        .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 301, Short.MAX_VALUE)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(235, 235, 235))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addGap(52, 52, 52)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addComponent(jButton2)
                .addContainerGap(42, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (jTable1.getSelectedRow() != (-1)) {
             LaboratorioBO labo = new LaboratorioBO();
             Laboratorio lab = labo.consultarLaboratorio((Integer) jTable1.getValueAt(jTable1.getSelectedRow(),
                     jTable1.getSelectedColumn()));
            ActualizarReporte(lab);
        }
        else {
            JOptionPane.showMessageDialog(this, "Lo sentimos!\n\nNo ha escogido un" +
                    "Laboratorio para Borrarr",
                    "Laboratorio Desconocido", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void ActualizarReporte(Laboratorio lab) {
        List<Asignatura> listaAsignaturas = asignaturabo.consultarAsignaturas();
        Asignatura asig = new Asignatura();
        asig.setNombreAsignatura("No tiene asignatura");
        for (int i = 0; i < listaAsignaturas.size(); i++){
            if (listaAsignaturas.get(i).getIdLaboratorio() == lab.getIdLaboratorio()){
                asig = listaAsignaturas.get(i);
            }
       }
        jTextField3.setText(asig.getNombreAsignatura());
        jTextField1.setText(lab.getcapacidadlab().toString());
        jTextField2.setText(lab.getdescripcionLab());
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InterfazReporteLaboratorio().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables

}
